import { createRouter, createWebHashHistory,createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import SearchView from '@/views/SearchView.vue'
import NotFind from '@/views/NotFind.vue'

const routes = [
  // 路径重定向
  { path: '/', redirect: '/home' },
  // 动态传参:words  这里直接跳转搜索页会导致报错找不到/search，因此需要将携带参数变为可选:words?
  { path: '/home', component: HomeView },
  { name:"search", path: '/search/:words?', component: SearchView },
  // 配置404  放在最后  catchAll抓取  .*所有
  { path: '/:catchAll(.*)', component: NotFind}
]

const router = createRouter({
  // 路由模式：createWebHashHistory  hash-》路径中带#
  // createWebHistory history -- >路径中不带#
  history: createWebHistory(),
  routes
})

export default router